import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;


public class Parts {
	LinkedList<Part> list;
	
	Parts(){
		list = new LinkedList<Part>();
	}
	
	void draw (Graphics2D context)
    {
        for (Part part : list)
        {
            if (part.life < 0.999)
            {
                part.draw(context);
            }
        }
    }
	
	void update (double time)
    {
		List<Part> toBeDeleted = new ArrayList<Part>();
		
        for (Part part : list)
        {
            part.life -= part.speed * time;
            if (part.life <= 0.001)
            {
            	toBeDeleted.add(part);
            }
            else if (part.life < 0.999)
            {
                part.x += time * part.vx;
                part.y += time * part.vy;
            }
        }
        for (Part part : toBeDeleted)
        	list.remove(part);
    }
	
	void add(Part part)
    {
        list.add(part);
    }
}
